package mystream;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.function.IntConsumer;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;

import static java.util.stream.Collectors.toList;

/**
 * Stream 流
 * range
 * foreach
 * map
 * collect
 *
 * ::new 条件 1.创建接口 接口有方法create new出来后传入构造参数得到对象
 * 类名::静态方法
 * 2020-11-06 11:28
 */
public class Study01 {
    public Study01(String s) {
        name = s;
    }

    public String name;

    public static void main(String[] args) {
        List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
        Stream<Integer> stream = numbers.stream();
        List<Integer> collect = stream.filter((x) -> {
            return x % 2 == 0;
        }).map((x) -> {
            return x * x;
        }).collect(Collectors.toList());
        System.out.println(collect.toString());
        IntStream.range(0,5).forEach(x-> System.out.println(x));
        InterfaceColomnDemo aNew =  Study01::new;

        Study01 yuxaing = aNew.create("yuxaing");
        System.out.println(yuxaing.name);
        Study01.print1();

        List<Integer> collect1 = IntStream.range(1, 1)
                .boxed()
                .collect(toList());
        System.out.println(collect1.toString());
        System.out.println(collect1.isEmpty());
        ArrayList<Object> list = new ArrayList<>(5);
        System.out.println(list);
        System.out.println(list);
    }

    public static void print1(){
        System.out.println("print1");
    }

}
